import { request } from '@umijs/max';
import { BaseResponse, PageInfo } from '@/golbal';
import { TeamType } from '@/models/team';

/***
 * 创建team
 * @param params
 */
export async function addTeam(params: TeamType.TeamAddRequest) {
  return request<BaseResponse<number>>('/team/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 删除team
 */
export async function deleteTeam(params: TeamType.TeamDeleteRequest) {
  return request<BaseResponse<boolean>>('/team/delete', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 更新队伍基础信息
 */
export async function updateBaseTeam(params: TeamType.TeamUpdateBaseRequest) {
  return request<BaseResponse<boolean>>('/team/update/base', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 更新公开的队伍信息
 */
export async function updateCureTeam(params: TeamType.TeamUpdateCureRequest) {
  return request<BaseResponse<number>>('/team/update/cure', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 * 管理员 查询 所有队伍
 */
export async function listQueryTeam(params: TeamType.TeamListQueryRequest) {
  return request<BaseResponse<PageInfo<TeamType.TeamVo[]>>>(
    '/team/list/query',
    {
      method: 'GET',
      params,
    },
  );
}
/**
 * 通过队伍 teamId 查询队伍信息
 */
export async function getQueryTeam(params: number) {
  return request<BaseResponse<TeamType.TeamVo>>('/team/get/query', {
    method: 'GET',
    teamId: params,
  });
}

/**
 *  创建队伍的审核通过
 */
export async function applyAdoptTeam(params: TeamType.TeamApplyAdoptRequest) {
  return request<BaseResponse<number>>('/team/apply/Adopt', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/**
 *  创建队伍的审核不通过
 */
export async function applyNoAdoptTeam(
  params: TeamType.TeamApplyNoAdoptRequest,
) {
  return request<BaseResponse<number>>('/team/apply/noAdopt', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 查询队伍自定义内容更改审核 默认查询为通过的队伍
 */
export async function listUpdateCureApplyTeam(
  params: TeamCureExamineType.TeamUpdateCureExamineRequest,
) {
  return request<BaseResponse<PageInfo<TeamType.TeamCureExamineVo[]>>>(
    '/team/list/examine',
    {
      method: 'GET',
      data: params,
    },
  );
}

/***
 * 队伍公开信息 更新审核通过
 */
export async function examineUpdateApplyTeam(
  params: TeamCureExamineType.TeamUpdateApplyRequest,
) {
  return request<BaseResponse<number>>('/team/update/apply', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 队伍公开信息 更新审核不通过
 */
export async function examineUpdateNoApplyTeam(
  params: TeamCureExamineType.TeamUpdateNoApplyRequest,
) {
  return request<BaseResponse<number>>('/team/update/noApply', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}
/***
 * 退出队伍
 */
export async function bowOutTeam(params: TeamType.TeamBowOutRequest) {
  return request<BaseResponse<number>>('/team/bowout', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * * 队伍 踢出成员
 */
export async function kickTeam(params: TeamType.TeamKickRequest) {
  return request<BaseResponse<number>>('/team/kick', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}
/***
 * 查看当前队伍成员信息
 */
export async function queryMemberTeam(params: TeamType.TeamQueryMemberRequest) {
  return request<BaseResponse<PageInfo<TeamType.UserTeamVo[]>>>(
    '/team/Query/member',
    {
      method: 'GET',
      params,
    },
  );
}

/***
 * 查看当前用户加入的队伍
 */
export async function listGetTeam() {
  return request<BaseResponse<TeamType.TeamVo>>('/team/list/get/team', {
    method: 'GET',
  });
}

/***
 * 查看当前用户创建的队伍
 */
export async function listGetQueryTeam() {
  return request<BaseResponse<TeamType.TeamVo>>('/team/list/get/query/team', {
    method: 'GET',
  });
}

/***
 * 查询当前队伍的信息
 */
export async function listMemberTeam(id: number) {
  return request<BaseResponse<TeamType.TeamVo>>('/team/list/member/team', {
    method: 'GET',
    params: { id },
  });
}

/***
 * * 转让队长 （现实基础操作）
 */
export async function captainLetTeam(params: TeamType.TeamCaptainLetRequest) {
  return request<BaseResponse<number>>('/team/let/captain', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 查询个人申请创建的队伍列表 listApplyTeam
 */
export async function listApplyTeam() {
  return request<BaseResponse<TeamType.TeamVo>>('/team/list/apply', {
    method: 'GET',
  });
}

/***
 * * 个人 删除还在申请中的队伍
 */
export async function deleteApplyTeam(params: TeamType.TeamDeleteApplyRequest) {
  return request<BaseResponse<number>>('/team/delete/apply', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}

/***
 * 查询所有审核通过的队伍
 */
export async function listOpenTeam(params: TeamType.TeamListQueryRequest) {
  return request<BaseResponse<TeamType.TeamVo>>('/team/list/open', {
    method: 'GET',
    params: params,
  });
}

/***
 *   * 管理员 修改 队伍信息
 */
export async function updateQueryTeam(params: TeamType.TeamUpdateQueryTeam) {
  return request<BaseResponse<number>>('/team/update/query', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}
